<?xml version="1.0" encoding="utf-8"?>
<!--
                                                                                     
 h       t     t                ::       /     /                     t             / 
 h       t     t                ::      //    //                     t            // 
 h     ttttt ttttt ppppp sssss         //    //  y   y       sssss ttttt         //  
 hhhh    t     t   p   p s            //    //   y   y       s       t          //   
 h  hh   t     t   ppppp sssss       //    //    yyyyy       sssss   t         //    
 h   h   t     t   p         s  ::   /     /         y  ..       s   t    ..   /     
 h   h   t     t   p     sssss  ::   /     /     yyyyy  ..   sssss   t    ..   /     
                                                                                     
	<https://y.st./>
	Copyright © 2016 Alex Yst <mailto:copyright@y.st>

	This program is free software: you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation, either version 3 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program. If not, see <https://www.gnu.org./licenses/>.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<base href="https://y.st./en/weblog/2016/11-November/28.xhtml"/>
		<title>I learned the secret to protecting values from closures. &lt;https://y.st./en/weblog/2016/11-November/28.xhtml&gt;</title>
		<link rel="icon" type="image/png" href="/link/CC_BY-SA_4.0/y.st./icon.png"/>
		<link rel="stylesheet" type="text/css" href="/link/main.css"/>
		<script type="text/javascript" src="/script/javascript.js"/>
		<meta name="viewport" content="width=device-width"/>
	</head>
	<body>
<nav>
	<p>
		<a href="/en/coursework/">Coursework</a> |
		<a href="/en/take-down/">Take-down requests</a> |
		<a href="/en/">Home</a> |
		<a href="/en/a/about.xhtml">About</a> |
		<a href="/en/a/contact.xhtml">Contact</a> |
		<a href="/a/canary.txt">Canary</a> |
		<a href="/en/URI_research/"><abbr title="Uniform Resource Identifier">URI</abbr> research</a> |
		<a href="/en/opinion/">Opinions</a> |
		<a href="/en/law/">Law</a> |
		<a href="/en/recipe/">Recipes</a> |
		<a href="/en/a/links.xhtml">Links</a> |
		<a href="/en/weblog/2016/11-November/28.xhtml.asc">{this page}.asc</a>
	</p>
	<hr/>
	<p>
		Weblog index:
		<a href="/en/weblog/memories">Memories</a> |
		<a href="/en/weblog/"><abbr title="American Standard Code for Information Interchange">ASCII</abbr> calendars</a> |
		<a href="/en/weblog/index_ol_ascending.xhtml">Ascending list</a> |
		<a href="/en/weblog/index_ol_descending.xhtml">Descending list</a>
	</p>
	<hr/>
	<p>
		Jump to entry:
		<a href="/en/weblog/2015/03-March/07.xhtml">&lt;&lt;First</a>
		<a rel="prev" href="/en/weblog/2016/11-November/27.xhtml">&lt;Previous</a>
		<a rel="next" href="/en/weblog/2016/11-November/29.xhtml">Next&gt;</a>
		<a href="/en/weblog/latest.xhtml">Latest&gt;&gt;</a>
			</p>
			<hr/>
</nav>
		<header>
			<h1>I learned the secret to protecting values from closures.</h1>
			<p>Day 00632: <time>Monday, 2016 November 28</time></p>
		</header>
<img src="/img/CC_BY-SA_4.0/y.st./weblog/2016/11/28.jpg" alt="A gated apartment complex" class="framed-centred-image" width="811" height="480"/>
<section id="general">
	<h2>General news</h2>
	<p>
		After my alarm went off, I must have fallen back asleep.
		It only felt like I continued laying down for a couple of minutes, but the next thing that I knew, more than half an hour had passed.
		I ended up having to skip picking up lunch on my way to work, and I still clocked in five minutes late.
		I made up for it though by staying an extra half hour when the shift leader in charge needed some extra manpower while waiting for the rest of the night crew to arrive.
	</p>
	<p>
		Professor Shyguy just opened preorders for their new album, <a href="https://professorshyguy.bandcamp.com/album/merry-chipmas-v-2">Merry Chipmas v.2</a>.
		Unlike the original Merry Chipmas, which was labeled as having all rights reserved, this album is covered by the <abbr title="Creative Commons Attribution 3.0 Unported">CC BY 3.0</abbr> license! It appears to have the original five songs from the first album, plus five more.
		Speaking of the first album, it&apos;s gone missing.
		Professor Shyguy has taken it off the market.
		The new album is scheduled to be released on 2016-12-01.
	</p>
	<p>
		My <a href="/a/canary.txt">canary</a> still sings the tune of freedom and transparency.
	</p>
</section>
<section id="include.d">
<h2><a href="https://git.volatile.ch./y.st./include.d/releases">include.d</a></h2>
<p>
	What if <abbr title="Uniform Resource Identifier">URI</abbr> components are stored in a static variable within a method? Is that possible? Would different instances of the class have different values in their static variables? Would closures be able to tamper with this variable? These are the questions that haunted me after I had a sudden flash of inspiration early this morning.
	As far as I can tell, there isn&apos;t a way for closures to tamper with this variable, provided that all of the normalization and validation features are supplied within the method itself.
	However, all instances of the class share a single copy of the variable.
	This can easily be fixed by making the variable an array and finding some way of granting each instance of the class a unique key.
	The key itself doesn&apos;t even need to be protected from closures.
	If closures tamper with the key, two objects will either share the same values or one object will have a bad key.
	I can either set the storage method to recover by assigning a default key or allow such objects to simply be broken.
	As long as no existing data set used by the class contains invalid <abbr title="Uniform Resource Identifier">URI</abbr> components, or a combination of valid <abbr title="Uniform Resource Identifier">URI</abbr> components that are invalid when used together, everything is awesome.
	Lastly, this tactic completely breaks the <code>\var_export()</code> function, as <code>\var_export()</code> won&apos;t see the data any more; after all, it won&apos;t be stored in properties at that point.
	I should probably implement some sort of workaround.
	One possibility would be to put a string copy of the <abbr title="Uniform Resource Identifier">URI</abbr> in a property.
	Closures would have access to this and be able to bork it, but that&apos;s about the best that I can do.
</p>
<p>
	The realization of how I might need to fix up my <abbr title="Uniform Resource Identifier">URI</abbr> classes once again came right after I finished bringing the <code>\st\y\uri\gopher</code> class up to speed with my last <abbr title="application programming interface">API</abbr> update.
	At first, I was thinking that hopefully not too much of my last <abbr title="application programming interface">API</abbr> update will go to waste.
	It&apos;s really a shame that I even have to jump through all these hoops just to keep my <abbr title="application programming interface">API</abbr> from being broken.
	Closures should not be allowed to break basic <abbr title="application programming interface">API</abbr> features.
	After thinking about his all day though, I came to the conclusion that it simply isn&apos;t worth it to work around this bug.
	Using a static variable containing an array would certainly have the effect that I&apos;m after, however, it breaks cloning and deconstructing features that are built into basic <abbr title="PHP: Hypertext Preprocessor">PHP</abbr> objects.
	I&apos;d have to do all cloning manually, which would certainly make my code less efficient, and if I failed to implement deconstructing manually, all past object data would be saved even after the objects are deleted.
	On a longer-running script that uses a lot of <abbr title="Uniform Resource Identifier">URI</abbr> objects, such as my onion spider, memory would fill up.
	You can&apos;t break my <abbr title="Uniform Resource Identifier">URI</abbr> objects accidentally, at least not with this closure feature.
	If you break my <abbr title="Uniform Resource Identifier">URI</abbr> objects in your script by using closures on them, you&apos;ve done it with intent to make the code fail.
	As such, I&apos;m just going to leave it alone.
	It&apos;s the problem of whoever causes it, not me.
	Now that I know how to protect variables, I can stop obsessing over this.
</p>
<p>
	I&apos;ve been working on my big <abbr title="Uniform Resource Identifier">URI</abbr> update for a while now.
	This update adds all scheme-specific <abbr title="Uniform Resource Identifier">URI</abbr> syntaxes to include.d as classes.
	However, this is boring.
	Educational, but very, very boring.
	I&apos;ve decided to attack the problem of scheme-specific <abbr title="Uniform Resource Identifier">URI</abbr> syntax in a different way.
	Instead of one big update, I&apos;ll add a few <abbr title="Uniform Resource Identifier">URI</abbr> schemes to each update.
	If the update is a 0.0.0.1-level or higher update, I&apos;ll add at least one permanent scheme, at least one historic scheme, and at least one provisional scheme.
	If I don&apos;t have those ready yet, I won&apos;t make a release yet.
	If I <strong>*do*</strong> have them ready though, I can (but do not have to) ignore the <abbr title="Uniform Resource Identifier">URI</abbr> code for the time being.
	Updates that are 0.0.0.0.1-level or below updates will be prohibited from introducing new <abbr title="Uniform Resource Identifier">URI</abbr> scheme classes.
</p>
</section>
<section id="apartment">
	<h2>Apartment hunting</h2>
	<p>
		I went to the apartment complex at which I filed my initial housing application, and had them update the telephone number that they have on file for me.
		Now if Google does end up revoking the telephone number that they issued me, the damage will be limited.
	</p>
</section>
		<hr/>
		<p>
			Copyright © 2016 Alex Yst;
			You may modify and/or redistribute this document under the terms of the <a rel="license" href="/license/gpl-3.0-standalone.xhtml"><abbr title="GNU&apos;s Not Unix">GNU</abbr> <abbr title="General Public License version Three or later">GPLv3+</abbr></a>.
			If for some reason you would prefer to modify and/or distribute this document under other free copyleft terms, please ask me via email.
			My address is in the source comments near the top of this document.
			This license also applies to embedded content such as images.
			For more information on that, see <a href="/en/a/licensing.xhtml">licensing</a>.
		</p>
		<p>
			<abbr title="World Wide Web Consortium">W3C</abbr> standards are important.
			This document conforms to the <a href="https://validator.w3.org./nu/?doc=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2016%2F11-November%2F28.xhtml"><abbr title="Extensible Hypertext Markup Language">XHTML</abbr> 5.2</a> specification and uses style sheets that conform to the <a href="http://jigsaw.w3.org./css-validator/validator?uri=https%3A%2F%2Fy.st.%2Fen%2Fweblog%2F2016%2F11-November%2F28.xhtml"><abbr title="Cascading Style Sheets">CSS</abbr>3</a> specification.
		</p>
	</body>
</html>

